package com.symone.webcms.schedule.job;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.symone.webcms.config.GlobalConfig;
import com.symone.webcms.model.LoginLog;
import com.symone.webcms.model.TaskLog;
import com.symone.webcms.model.UserLog;
import com.symone.webcms.schedule.BaseJob;
import com.symone.webcms.service.LoginLogService;
import com.symone.webcms.service.TaskLogService;
import com.symone.webcms.service.UserLogService;
import com.symone.webcms.util.SpringUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

public class JobLogService{

    public void run() {
        Integer sysLogDates = Integer.valueOf(GlobalConfig.getInstance().get("sys_log_dates"));
        Integer loginLogDates = Integer.valueOf(GlobalConfig.getInstance().get("sys_log_login_dates"));
        Integer taskLogDates = Integer.valueOf(GlobalConfig.getInstance().get("sys_log_task_dates"));
        UserLogService userLogService = (UserLogService) SpringUtil.getBean(UserLogService.class);
        LoginLogService loginLogService = (LoginLogService) SpringUtil.getBean(LoginLogService.class);
        TaskLogService taskLogService = (TaskLogService) SpringUtil.getBean(TaskLogService.class);
        userLogService.delete(new EntityWrapper<UserLog>().gt("DATEDIFF(NOW(),create_time)",sysLogDates));
        loginLogService.delete(new EntityWrapper<LoginLog>().gt("DATEDIFF(NOW(),create_time)",loginLogDates));
        taskLogService.delete(new EntityWrapper<TaskLog>().gt("DATEDIFF(NOW(),create_time)",taskLogDates));
    }
}

